package com.galen.manual.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

@Data
@EqualsAndHashCode(callSuper = true)
@TableName("admins")
public class Admin extends BaseEntity {

    @TableField("user_id")
    private Long userId;

    @TableField("role")
    private String role; // super-超级管理员，admin-普通管理员

    @TableField("status")
    private Integer status; // 0-禁用 1-启用

    @TableField("last_login_time")
    private LocalDateTime lastLoginTime;

    @TableField("last_login_ip")
    private String lastLoginIp;

    // 关联查询字段（不存储在数据库中）
    @TableField(exist = false)
    private String username;

    @TableField(exist = false)
    private String nickname;

    @TableField(exist = false)
    private String phone;

    @TableField(exist = false)
    private String avatarUrl;

    @Override
    public void preInsert() {
        super.preInsert();
        // 管理员特定的初始化逻辑
        if (this.status == null) {
            this.status = 1;
        }
        if (this.role == null) {
            this.role = "admin";
        }
    }
}